Conversation
| .toList(); | ||
| assertThat(ids).contains(subscriptionFirst.getId(), subscriptionSecond.getId(), | ||
| subscriptionThird.getId()); | ||
| } |
There was a problem hiding this comment.
Разделяй четко 3 секции в тесте, чтобы улучшить его читабильность: given/when/then
| List<Integer> ids = result.stream() | ||
| .map(Subscription::getId) | ||
| .toList(); | ||
| assertThat(ids).contains(subscriptionFirst.getId(), subscriptionSecond.getId(), |
There was a problem hiding this comment.
нет смысла в этом ассерте, когда есть assertEquals такой чуть выше
| var result = subscriptionDao.delete(subscriptionFirst.getId()); | ||
|
|
||
| assertTrue(result); | ||
|
|
There was a problem hiding this comment.
не надо делать отступов в конце метода
| void deleteWhenIdNotExistsThenReturnFalse() { | ||
| subscriptionDao.insert(getSubscription("first")); | ||
|
|
||
| var result = subscriptionDao.delete(1234); |
There was a problem hiding this comment.
нужно выбирать более нереалистичное значение id
1234 легко достичь в тестах, что приведет к его flaky
| var subscriptionFirst = subscriptionDao.insert(getSubscription("first").setUserId(userid)); | ||
| var subscriptionSecond = subscriptionDao.insert(getSubscription("second").setUserId(userid)); | ||
|
|
||
| List<Subscription> result = subscriptionDao.findByUserId(userid); |
There was a problem hiding this comment.
Для теста метода findByUserId нужна вставить несколько подписок с разным userId - иначе некорректный dataset. Его можно заменить на findAll, например, и он все еще будет проходить
| private CreateSubscriptionValidator createSubscriptionValidator; | ||
|
|
||
| @Mock | ||
| private Clock clock; |
There was a problem hiding this comment.
Clock не мокают обычно. Этот класс используется сам по себе для тестов. Почитать документацию его
|
|
||
| @Test | ||
| void whenCallingUpsertMethodWithInvalidDtoThenThrowValidationException() { | ||
| var dto = Mockito.mock(CreateSubscriptionDto.class); |
There was a problem hiding this comment.
мокают обычно только зависимости в логике, а не данные. Данные используют максимально реалистичные
| subscriptionService.cancel(any()); | ||
|
|
||
| verify(subscriptionDao, times(1)).update(updatedSubscription); | ||
| verify(subscriptionDao, times(1)).findById(any()); |
There was a problem hiding this comment.
times(1) - это по умолчанию. Нет смысла указывать дефолты явно
|
|
||
| class PropertiesUtilTest { | ||
|
|
||
|
|
There was a problem hiding this comment.
1 строки отступа достаточно между классом и его полями/методами
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class SubscriptionServiceTest { |
There was a problem hiding this comment.
надо все методы покрыть было интеграционными тестами. SubscriptionService - это самый важный сервис!
No description provided.